﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Forecast.Logica.Enumeradores
Imports Forecast.Logica.Servicios
Imports Forecast.Logica.Modelos
Public Class CrtListado
    Inherits System.Web.UI.UserControl
    Private Shared _ServForecast As ServForecast


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("ActualizarListado") = True Then
            Session("ActualizarListado") = False
            CargarListado()
        End If
    End Sub
    Public Function CargarListado()
        '_ServForecast = New ServForecast()
        'Dim Usuario = Session("usuario")
        'Dim IdEntidad As Integer
        'If Session("IdEntidad") IsNot Nothing Then
        '    IdEntidad = Session("IdEntidad")
        'Else
        '    IdEntidad = Usuario.IdEntityF
        'End If
        'Dim TBProductoDeForecast = _ServForecast.Search_ForeCastDeUsuario(Usuario.IdUsuario, IdEntidad)  '# DEJAR PARAMETRIZADO
        'Dim codCliente, IdProductLine As Integer
        'Dim I As Integer
        'Dim H As Integer

        'Try
        '    Dim table As DataTable = New DataTable("Tabla1")

        '    table.Columns.Add(New DataColumn("IdCustomer", GetType(String)))
        '    table.Columns.Add(New DataColumn("Cliente", GetType(String)))
        '    table.Columns.Add(New DataColumn("IdSegment", GetType(String)))
        '    table.Columns.Add(New DataColumn("Segmento", GetType(String)))
        '    table.Columns.Add(New DataColumn("IdProductLine", GetType(String)))
        '    table.Columns.Add(New DataColumn("ProdutLine", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes1", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes2", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes3", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes4", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes5", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes6", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes7", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes8", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes9", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes10", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes11", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes12", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes13", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes14", GetType(String)))
        '    table.Columns.Add(New DataColumn("Mes15", GetType(String)))

        '    If TBProductoDeForecast.Rows.Count > 0 Then
        '        'Ahora creamos filas para que la tabla tenga datos
        '        Dim row As DataRow = table.NewRow()
        '        For k = 0 To TBProductoDeForecast.Rows.Count - 1 Step 1
        '            If codCliente <> TBProductoDeForecast.Rows(k).Item("IdCustomer") Or IdProductLine <> TBProductoDeForecast.Rows(k).Item("IdProductLine") Then
        '                codCliente = TBProductoDeForecast.Rows(k).Item("IdCustomer")
        '                IdProductLine = TBProductoDeForecast.Rows(k).Item("IdProductLine")

        '                If k > 0 Then
        '                    table.Rows.Add(row)
        '                End If
        '                row = table.NewRow()
        '                I = 0
        '                row("IdCustomer") = TBProductoDeForecast.Rows(k).Item("IdCustomer")
        '                row("Cliente") = TBProductoDeForecast.Rows(k).Item("Cliente")
        '                row("IdSegment") = TBProductoDeForecast.Rows(k).Item("IdSegment")
        '                row("Segmento") = TBProductoDeForecast.Rows(k).Item("DesSegment")
        '                row("IdProductLine") = TBProductoDeForecast.Rows(k).Item("IdProductLine")
        '                row("ProdutLine") = TBProductoDeForecast.Rows(k).Item("DesProductLine")
        '            End If
        '            GridView1.Columns(I + 7).HeaderText = TBProductoDeForecast.Rows(k).Item("DesPeriodo")

        '            If I = 0 Then : row("Mes1") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 1 Then : row("Mes2") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 2 Then : row("Mes3") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 3 Then : row("Mes4") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 4 Then : row("Mes5") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 5 Then : row("Mes6") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 6 Then : row("Mes7") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 7 Then : row("Mes8") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 8 Then : row("Mes9") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 9 Then : row("Mes10") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 10 Then : row("Mes11") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 11 Then : row("Mes12") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 12 Then : row("Mes13") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 13 Then : row("Mes14") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If
        '            If I = 14 Then : row("Mes15") = TBProductoDeForecast.Rows(k).Item("ValuesSP") : End If

        '            I = I + 1
        '        Next
        '        table.Rows.Add(row)
        '    End If
        '    Session("TBListado") = table
        '    GridView1.DataSource = table
        '    GridView1.DataBind()
        'Catch ex As Exception

        'End Try

    End Function
    Private Function CargaParamBusqueda(IdCustomer As Integer, IdSegmento As Integer, IdProductLine As Integer) As BusForecast

        Dim BusForecast = New BusForecast()
        BusForecast.IdCustomer = IdCustomer 'DrClientesB.SelectedValue
        BusForecast.IdUOM = 0 'DrUOMB.SelectedValue
        'If DrProductoB.SelectedValue <> "" Then
        '    BusForecast.IdProduct = CInt(DrProductoB.SelectedValue)
        'End If
        BusForecast.IdSegmento = IdSegmento 'DrSegmentoPLB.SelectedValue
        BusForecast.IdProductLine = IdProductLine 'DrProductLineB.SelectedValue
        BusForecast.CodCustomer = "" 'TxtCodClienteB.Text
        Return BusForecast

    End Function

    Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "Select" Then
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim IdCustomer, IdSegment, IdProductLine As Integer
            IdCustomer = Session("TBListado").rows(index).Item("IdCustomer").ToString
            IdSegment = Session("TBListado").rows(index).Item("IdSegment").ToString
            IdProductLine = Session("TBListado").rows(index).Item("IdProductLine").ToString
            Dim _BusForecast = CargaParamBusqueda(IdCustomer, IdSegment, IdProductLine)

            ' ctrlAgregarForecast1.CargarProductoDeForecast(_BusForecast)

        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' ctrlAgregarForecast1.SoloIngreso()
    End Sub
End Class